﻿Imports org.codegen.win.controls.Grid
Imports IIC.Forms.List
Imports IICBusinessLogic

Namespace Forms.Edit

    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Public Class frmStudentDetails
        Inherits org.codegen.win.controls.frmBaseEdit


#Region "Designer"

        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub

        Friend WithEvents dcCertificationEarnedId As System.Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents dcCertificationType As System.Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents dcEarnedDate As org.codegen.win.controls.DataGridViewCalendarColumn

        Friend WithEvents dcDiplomaEarnedId As System.Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents dcDiplomaType As System.Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents dcDiplomaEarnedDate As org.codegen.win.controls.DataGridViewCalendarColumn
        Friend WithEvents TabStudent As System.Windows.Forms.TabControl
        Friend WithEvents TabPageStudent As System.Windows.Forms.TabPage
        Friend WithEvents UcStudent As IIC.ucStudentDetails

        Friend WithEvents tabPageCerts As System.Windows.Forms.TabPage
        Friend WithEvents Label1 As System.Windows.Forms.Label
        Friend WithEvents Label2 As System.Windows.Forms.Label
        Friend WithEvents tabPageStudentCredits As System.Windows.Forms.TabPage
        Friend WithEvents pnlDiplomas As System.Windows.Forms.Panel
        Friend WithEvents pnlCertifications As System.Windows.Forms.Panel
        Friend WithEvents grdCerts As org.codegen.win.controls.Grid.ucObjectListGrid
        Friend WithEvents CertificationEarnedId As System.Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents CertificationType As System.Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents EarnedDate As org.codegen.win.controls.DataGridViewCalendarColumn
        Friend WithEvents grdDiplomas As org.codegen.win.controls.Grid.ucObjectListGrid
        Friend WithEvents DiplomaEarnedId As System.Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents DiplomaType As System.Windows.Forms.DataGridViewTextBoxColumn
        Friend WithEvents DiplomaEarnedDate As org.codegen.win.controls.DataGridViewCalendarColumn
        Friend WithEvents ucStudentHistory As IIC.ucStudentHistory


        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Dim DataGridViewCellStyle1 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle()
            Dim DataGridViewCellStyle3 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle()
            Dim DataGridViewCellStyle2 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle()
            Dim DataGridViewCellStyle4 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle()
            Dim DataGridViewCellStyle6 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle()
            Dim DataGridViewCellStyle5 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle()
            Me.TabStudent = New System.Windows.Forms.TabControl()
            Me.TabPageStudent = New System.Windows.Forms.TabPage()
            Me.ucStudentHistory = New IIC.ucStudentHistory()
            Me.UcStudent = New IIC.ucStudentDetails()
            Me.tabPageCerts = New System.Windows.Forms.TabPage()
            Me.pnlCertifications = New System.Windows.Forms.Panel()
            Me.grdCerts = New org.codegen.win.controls.Grid.ucObjectListGrid()
            Me.CertificationEarnedId = New System.Windows.Forms.DataGridViewTextBoxColumn()
            Me.CertificationType = New System.Windows.Forms.DataGridViewTextBoxColumn()
            Me.EarnedDate = New org.codegen.win.controls.DataGridViewCalendarColumn()
            Me.pnlDiplomas = New System.Windows.Forms.Panel()
            Me.grdDiplomas = New org.codegen.win.controls.Grid.ucObjectListGrid()
            Me.DiplomaEarnedId = New System.Windows.Forms.DataGridViewTextBoxColumn()
            Me.DiplomaType = New System.Windows.Forms.DataGridViewTextBoxColumn()
            Me.DiplomaEarnedDate = New org.codegen.win.controls.DataGridViewCalendarColumn()
            Me.Label2 = New System.Windows.Forms.Label()
            Me.Label1 = New System.Windows.Forms.Label()
            Me.tabPageStudentCredits = New System.Windows.Forms.TabPage()
            Me.TabStudent.SuspendLayout()
            Me.TabPageStudent.SuspendLayout()
            Me.tabPageCerts.SuspendLayout()
            Me.pnlCertifications.SuspendLayout()
            CType(Me.grdCerts, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.pnlDiplomas.SuspendLayout()
            CType(Me.grdDiplomas, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'UcEditToolar
            '
            Me.UcEditToolar.ShowAdd = True
            Me.UcEditToolar.ShowDelete = True
            Me.UcEditToolar.ShowNavigationButtons = True
            Me.UcEditToolar.Size = New System.Drawing.Size(944, 30)
            '
            'TabStudent
            '
            Me.TabStudent.Controls.Add(Me.TabPageStudent)
            Me.TabStudent.Controls.Add(Me.tabPageCerts)
            Me.TabStudent.Controls.Add(Me.tabPageStudentCredits)
            Me.TabStudent.Dock = System.Windows.Forms.DockStyle.Fill
            Me.TabStudent.Location = New System.Drawing.Point(0, 30)
            Me.TabStudent.Name = "TabStudent"
            Me.TabStudent.SelectedIndex = 0
            Me.TabStudent.Size = New System.Drawing.Size(944, 650)
            Me.TabStudent.TabIndex = 3
            '
            'TabPageStudent
            '
            Me.TabPageStudent.Controls.Add(Me.ucStudentHistory)
            Me.TabPageStudent.Controls.Add(Me.UcStudent)
            Me.TabPageStudent.Location = New System.Drawing.Point(4, 22)
            Me.TabPageStudent.Name = "TabPageStudent"
            Me.TabPageStudent.Padding = New System.Windows.Forms.Padding(3)
            Me.TabPageStudent.Size = New System.Drawing.Size(936, 624)
            Me.TabPageStudent.TabIndex = 0
            Me.TabPageStudent.Text = "Personal Info"
            Me.TabPageStudent.UseVisualStyleBackColor = True
            '
            'UcStudEnterStudentGrades
            '
            Me.ucStudentHistory.Location = New System.Drawing.Point(50, 375)
            Me.ucStudentHistory.Name = "UcStudEnterStudentGrades"
            Me.ucStudentHistory.Size = New System.Drawing.Size(867, 213)
            Me.ucStudentHistory.TabIndex = 2
            '
            'UcStudent
            '
            Me.UcStudent.AutoValidate = System.Windows.Forms.AutoValidate.EnableAllowFocusChange
            Me.UcStudent.Dock = System.Windows.Forms.DockStyle.Fill
            Me.UcStudent.isInitialized = False
            Me.UcStudent.Location = New System.Drawing.Point(3, 3)
            Me.UcStudent.ModelObject = Nothing
            Me.UcStudent.Name = "UcStudent"
            Me.UcStudent.Size = New System.Drawing.Size(930, 618)
            Me.UcStudent.TabIndex = 1
            '
            'tabPageCerts
            '
            Me.tabPageCerts.Controls.Add(Me.pnlCertifications)
            Me.tabPageCerts.Controls.Add(Me.pnlDiplomas)
            Me.tabPageCerts.Controls.Add(Me.Label2)
            Me.tabPageCerts.Controls.Add(Me.Label1)
            Me.tabPageCerts.Location = New System.Drawing.Point(4, 22)
            Me.tabPageCerts.Name = "tabPageCerts"
            Me.tabPageCerts.Padding = New System.Windows.Forms.Padding(3)
            Me.tabPageCerts.Size = New System.Drawing.Size(936, 624)
            Me.tabPageCerts.TabIndex = 1
            Me.tabPageCerts.Text = "Diplomas and Certifications Earned"
            Me.tabPageCerts.UseVisualStyleBackColor = True
            '
            'pnlCertifications
            '
            Me.pnlCertifications.Controls.Add(Me.grdCerts)
            Me.pnlCertifications.Location = New System.Drawing.Point(108, 212)
            Me.pnlCertifications.Name = "pnlCertifications"
            Me.pnlCertifications.Size = New System.Drawing.Size(622, 138)
            Me.pnlCertifications.TabIndex = 8
            '
            'grdCerts
            '
            Me.grdCerts.AllowUserToAddRows = False
            Me.grdCerts.AllowUserToDeleteRows = False
            Me.grdCerts.AllowUserToOrderColumns = True
            Me.grdCerts.AllowUserToResizeRows = False
            DataGridViewCellStyle1.BackColor = System.Drawing.Color.AntiqueWhite
            Me.grdCerts.AlternatingRowsDefaultCellStyle = DataGridViewCellStyle1
            Me.grdCerts.BackgroundColor = System.Drawing.SystemColors.Window
            Me.grdCerts.BindingSource = Nothing
            Me.grdCerts.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.SingleHorizontal
            Me.grdCerts.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
            Me.grdCerts.ColumnIndexToHide = 0
            Me.grdCerts.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.CertificationEarnedId, Me.CertificationType, Me.EarnedDate})
            Me.grdCerts.DBMapper = Nothing
            Me.grdCerts.Dock = System.Windows.Forms.DockStyle.Fill
            Me.grdCerts.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically
            Me.grdCerts.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.grdCerts.gpEditForm = Nothing
            Me.grdCerts.gpKeyColumnName = Nothing
            Me.grdCerts.gpSortColumn = Nothing
            Me.grdCerts.gpSortDirection = System.ComponentModel.ListSortDirection.Ascending
            Me.grdCerts.GridColor = System.Drawing.SystemColors.Control
            Me.grdCerts.GridColumnProvider = Nothing
            Me.grdCerts.isLocalizable = False
            Me.grdCerts.Location = New System.Drawing.Point(0, 0)
            Me.grdCerts.Name = "grdCerts"
            Me.grdCerts.ReadOnly = True
            DataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Desktop
            DataGridViewCellStyle3.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            DataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText
            DataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight
            DataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText
            Me.grdCerts.RowHeadersDefaultCellStyle = DataGridViewCellStyle3
            Me.grdCerts.RowHeadersVisible = False
            Me.grdCerts.RowTemplate.Height = 20
            Me.grdCerts.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect
            Me.grdCerts.Size = New System.Drawing.Size(622, 138)
            Me.grdCerts.TabIndex = 5
            '
            'CertificationEarnedId
            '
            Me.CertificationEarnedId.DataPropertyName = "CertificationEarnedId"
            Me.CertificationEarnedId.HeaderText = "CertificationEarnedId"
            Me.CertificationEarnedId.Name = "CertificationEarnedId"
            Me.CertificationEarnedId.ReadOnly = True
            Me.CertificationEarnedId.Visible = False
            '
            'CertificationType
            '
            Me.CertificationType.DataPropertyName = "CertificationType"
            Me.CertificationType.HeaderText = "Certification"
            Me.CertificationType.Name = "CertificationType"
            Me.CertificationType.ReadOnly = True
            Me.CertificationType.Width = 400
            '
            'EarnedDate
            '
            Me.EarnedDate.DataPropertyName = "EarnedDate"
            Me.EarnedDate.DefaultCellStyle = DataGridViewCellStyle2
            Me.EarnedDate.HeaderText = "Earned Date"
            Me.EarnedDate.Name = "EarnedDate"
            Me.EarnedDate.ReadOnly = True
            Me.EarnedDate.Resizable = System.Windows.Forms.DataGridViewTriState.[True]
            Me.EarnedDate.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic
            '
            'pnlDiplomas
            '
            Me.pnlDiplomas.Controls.Add(Me.grdDiplomas)
            Me.pnlDiplomas.Location = New System.Drawing.Point(108, 45)
            Me.pnlDiplomas.Name = "pnlDiplomas"
            Me.pnlDiplomas.Size = New System.Drawing.Size(622, 134)
            Me.pnlDiplomas.TabIndex = 7
            '
            'grdDiplomas
            '
            Me.grdDiplomas.AllowUserToAddRows = False
            Me.grdDiplomas.AllowUserToDeleteRows = False
            Me.grdDiplomas.AllowUserToOrderColumns = True
            Me.grdDiplomas.AllowUserToResizeRows = False
            DataGridViewCellStyle4.BackColor = System.Drawing.Color.AntiqueWhite
            Me.grdDiplomas.AlternatingRowsDefaultCellStyle = DataGridViewCellStyle4
            Me.grdDiplomas.BackgroundColor = System.Drawing.SystemColors.Window
            Me.grdDiplomas.BindingSource = Nothing
            Me.grdDiplomas.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.SingleHorizontal
            Me.grdDiplomas.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
            Me.grdDiplomas.ColumnIndexToHide = 0
            Me.grdDiplomas.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.DiplomaEarnedId, Me.DiplomaType, Me.DiplomaEarnedDate})
            Me.grdDiplomas.DBMapper = Nothing
            Me.grdDiplomas.Dock = System.Windows.Forms.DockStyle.Fill
            Me.grdDiplomas.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically
            Me.grdDiplomas.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.grdDiplomas.gpEditForm = Nothing
            Me.grdDiplomas.gpKeyColumnName = Nothing
            Me.grdDiplomas.gpSortColumn = Nothing
            Me.grdDiplomas.gpSortDirection = System.ComponentModel.ListSortDirection.Ascending
            Me.grdDiplomas.GridColor = System.Drawing.SystemColors.Control
            Me.grdDiplomas.GridColumnProvider = Nothing
            Me.grdDiplomas.isLocalizable = False
            Me.grdDiplomas.Location = New System.Drawing.Point(0, 0)
            Me.grdDiplomas.MultiSelect = False
            Me.grdDiplomas.Name = "grdDiplomas"
            Me.grdDiplomas.ReadOnly = True
            DataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Desktop
            DataGridViewCellStyle6.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            DataGridViewCellStyle6.ForeColor = System.Drawing.SystemColors.WindowText
            DataGridViewCellStyle6.SelectionBackColor = System.Drawing.SystemColors.Highlight
            DataGridViewCellStyle6.SelectionForeColor = System.Drawing.SystemColors.HighlightText
            Me.grdDiplomas.RowHeadersDefaultCellStyle = DataGridViewCellStyle6
            Me.grdDiplomas.RowHeadersVisible = False
            Me.grdDiplomas.RowTemplate.Height = 20
            Me.grdDiplomas.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect
            Me.grdDiplomas.Size = New System.Drawing.Size(622, 134)
            Me.grdDiplomas.TabIndex = 4
            '
            'DiplomaEarnedId
            '
            Me.DiplomaEarnedId.DataPropertyName = "DiplomaEarnedId"
            Me.DiplomaEarnedId.HeaderText = "DiplomaEarnedId"
            Me.DiplomaEarnedId.Name = "DiplomaEarnedId"
            Me.DiplomaEarnedId.ReadOnly = True
            Me.DiplomaEarnedId.Visible = False
            '
            'DiplomaType
            '
            Me.DiplomaType.DataPropertyName = "DiplomaType"
            Me.DiplomaType.HeaderText = "Diploma"
            Me.DiplomaType.Name = "DiplomaType"
            Me.DiplomaType.ReadOnly = True
            Me.DiplomaType.Width = 400
            '
            'DiplomaEarnedDate
            '
            Me.DiplomaEarnedDate.DataPropertyName = "EarnedDate"
            Me.DiplomaEarnedDate.DefaultCellStyle = DataGridViewCellStyle5
            Me.DiplomaEarnedDate.HeaderText = "Earned Date"
            Me.DiplomaEarnedDate.Name = "DiplomaEarnedDate"
            Me.DiplomaEarnedDate.ReadOnly = True
            Me.DiplomaEarnedDate.Resizable = System.Windows.Forms.DataGridViewTriState.[True]
            Me.DiplomaEarnedDate.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic
            '
            'Label2
            '
            Me.Label2.AutoSize = True
            Me.Label2.Location = New System.Drawing.Point(69, 29)
            Me.Label2.Name = "Label2"
            Me.Label2.Size = New System.Drawing.Size(104, 13)
            Me.Label2.TabIndex = 6
            Me.Label2.Text = "Earned Diplomas"
            '
            'Label1
            '
            Me.Label1.AutoSize = True
            Me.Label1.Location = New System.Drawing.Point(69, 196)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(116, 13)
            Me.Label1.TabIndex = 5
            Me.Label1.Text = "Earned Certificates"
            '
            'tabPageExceptions
            '
            Me.tabPageStudentCredits.Location = New System.Drawing.Point(4, 22)
            Me.tabPageStudentCredits.Name = "tabPageStudentCredits"
            Me.tabPageStudentCredits.Padding = New System.Windows.Forms.Padding(3)
            Me.tabPageStudentCredits.Size = New System.Drawing.Size(936, 624)
            Me.tabPageStudentCredits.TabIndex = 3
            Me.tabPageStudentCredits.Text = "Lesson Credits"
            Me.tabPageStudentCredits.UseVisualStyleBackColor = True
            '
            'frmStudentDetails
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(7.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(944, 702)
            Me.Controls.Add(Me.TabStudent)
            Me.Name = "frmStudentDetails"
            Me.ShowAdd = True
            Me.ShowDelete = True
            Me.ShowNavigationButtons = True
            Me.Text = "Student Information"
            Me.Controls.SetChildIndex(Me.UcEditToolar, 0)
            Me.Controls.SetChildIndex(Me.TabStudent, 0)
            Me.TabStudent.ResumeLayout(False)
            Me.TabPageStudent.ResumeLayout(False)
            Me.tabPageCerts.ResumeLayout(False)
            Me.tabPageCerts.PerformLayout()
            Me.pnlCertifications.ResumeLayout(False)
            CType(Me.grdCerts, System.ComponentModel.ISupportInitialize).EndInit()
            Me.pnlDiplomas.ResumeLayout(False)
            CType(Me.grdDiplomas, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)
            Me.PerformLayout()

        End Sub


#End Region

#Region "Standard Code"

        Public Overrides Sub DeleteData()

            Dim mapper As StudentDBMapper = New StudentDBMapper()
            mapper.deleteByKey(Me.IdValue)

            'after delete, close the form
            'Note: do not set the dialog result here.  It is handled by the frmBaseEdit, ie do not call Me.DialogResult = Windows.Forms.DialogResult.None

        End Sub

        Public Overrides Sub LoadData()

            Me.UcStudent.ModelObject = New StudentDBMapper().findByKey(Me.IdValue)
            Me.UcStudent.loadData()

            Me.UcStudent.UcStudentMembershipDetails.ModelObject = Me.UcStudent.ModelObject
            Me.UcStudent.UcStudentMembershipDetails.loadData()

            Me.grdCerts.AutoGenerateColumns = False
            Me.grdDiplomas.AutoGenerateColumns = False

            Me.grdCerts.DataSource = CType(Me.UcStudent.ModelObject, Student).CertificationsEarned
            Me.grdDiplomas.DataSource = CType(Me.UcStudent.ModelObject, Student).DiplomasEarned

            While Me.grdDiplomas.SelectedRows.Count > 0
                Me.grdDiplomas.SelectedRows(0).Selected = False
            End While
            While Me.grdCerts.SelectedRows.Count > 0
                Me.grdCerts.SelectedRows(0).Selected = False
            End While

            Me.setRecordLoadedStatus(Me.IdValue)

            'reset load flag of classes attended
            Me.classesAttendedLoaded = False
            Me.StudentCreditsLoaded = False

            Call checkPageStudentCreditsForm()

            If Me.IdValue = 0 Then
                Me.TabStudent.SelectedTab = Me.TabStudent.TabPages(0)
                Me.ucStudentHistory.clearHistory()

            Else
                Me.ucStudentHistory.loadHistory(Me.IdValue)
                If Me.TabStudent.SelectedIndex = TAB_INDEX_CREDITS Then
                    Me.loadStudentCredits()
                End If

            End If

            Me.Text = Application.OpenForms("frmMain").Text & " "
            Me.Text &= Me.UcStudent.FirstName.Text & " " & Me.UcStudent.LastName.Text

            Me.UcStudent.resetLastLoadedValues()
        End Sub


        Public Overrides Function SaveData() As enumSaveDataResult

            If Me.ValidateChildren() Then

                Me.UcStudent.loadToObject()
                Me.UcStudent.UcStudentMembershipDetails.loadToObject()

                Dim db As New StudentDBMapper()
                db.save(Me.UcStudent.ModelObject)

                Me.addStudentToClasses()

                'CALL RELOAD DATA TO REFRESH WINDOW
                Call LoadData()

                Return enumSaveDataResult.SAVE_SUCESS_AND_STAY 'we will return false so that we do not close the form. We need to keep the form open

            Else
                Return enumSaveDataResult.SAVE_FAIL
            End If

        End Function

        Public Overrides Function dataChanged() As Boolean

            Return Me.UcStudent.hasChanges

        End Function

#End Region

#Region "Custom Code"


        Private Const TAB_INDEX_CREDITS As Integer = 2

        ''' <summary>
        ''' Flag to indicate if classes attended of the student in tab have been loaded or not
        ''' </summary>
        Private classesAttendedLoaded As Boolean = False

        ''' <summary>
        ''' Flag to indicate if classes attended of the student in tab have been loaded or not
        ''' </summary>
        Private StudentCreditsLoaded As Boolean = False


        ''' <summary>
        ''' Loads classes attended by a student
        ''' </summary>
        Private Sub loadStudentCredits()

            If Me.StudentCreditsLoaded Then Exit Sub

            CType(Me.tabPageStudentCredits.Controls(0), frmStudentLessonCreditList). _
                    ucStudentLessonExceptionList.loadStudentExceptions(Me.IdValue)

            CType(Me.tabPageStudentCredits.Controls(0), frmStudentLessonCreditList). _
                DefaultStudentId = Me.IdValue

            Me.StudentCreditsLoaded = True

        End Sub


        Private Sub TabStudent_TabIndexChanged(ByVal sender As System.Object, _
                    ByVal e As System.Windows.Forms.TabControlEventArgs) _
                                                Handles TabStudent.Selected

            If e.Action = TabControlAction.Selected Then
                If e.TabPageIndex = TAB_INDEX_CREDITS Then
                    Me.loadStudentCredits()
                End If
            End If

        End Sub

#End Region

#Region "Form Events"

        Private Sub frmStudentDetails_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

            While Me.tabPageStudentCredits.Controls.Count > 0
                Dim ctrl As Control = Me.tabPageStudentCredits.Controls(0)
                Me.tabPageStudentCredits.Controls.RemoveAt(0)
                ctrl.Dispose()
            End While

        End Sub

        Private Sub frmLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            Me.UcStudent.resetLastLoadedValues()

            Dim selectClasses As String = "isOpen=1"
            If (My.Settings.CurrentPeriodId <> 0) Then
                selectClasses &= " and periodid=" & My.Settings.CurrentPeriodId
            End If

            Me.UcStudent.UcPeriodClassList.FromEmployeeScreen = True
            Me.UcStudent.UcPeriodClassList.grdPeriodClass.gpWhereclause = selectClasses
            Me.UcStudent.UcPeriodClassList.grdPeriodClass.loadGrid()
            Me.UcStudent.UcPeriodClassList.grdPeriodClass.ClearSelection()

            Dim f As New frmStudentLessonCreditList
            f.ShowExcelButton = False
            f.TopLevel = False
            f.FormBorderStyle = Windows.Forms.FormBorderStyle.None
            f.Visible = True
            'f.Name = "frmStudentLessonCreditList"
            f.Dock = DockStyle.Fill
            Me.tabPageStudentCredits.Controls.Add(f)
            Call checkPageStudentCreditsForm()

        End Sub

        ''' <summary>
        ''' when "new" student mode, do not allow adding exceptions
        ''' </summary>
        Private Sub checkPageStudentCreditsForm()
            If Me.tabPageStudentCredits.Controls.Count > 0 Then

                If Me.NewRecord Then
                    CType(Me.tabPageStudentCredits.Controls(0), frmStudentLessonCreditList).setReadOnly()
                End If

            End If

        End Sub

        ''' <summary>
        ''' adds the student as a classMember upon save
        ''' </summary>
        ''' <remarks></remarks>
        Private Sub addStudentToClasses()

            Dim sman As IStudentClassManager = New StudentClassManagerFactory().getStudentClassManager
            Dim db As New PeriodClassDBMapper()

            For Each itm As DataGridViewRow In Me.UcStudent.UcPeriodClassList.grdPeriodClass.SelectedRows

                'validate that a period class exists for the selected 
                'period and lasson id selected
                Dim periodClass As PeriodClass = PeriodClassDataUtils.findByKey(CInt(itm.Cells("ClassId").Value))

                If periodClass Is Nothing Then
                    Call winUtils.MsgboxStop("There is no Class for the period and lesson you selected.")
                End If

                Call sman.addStudentToClass( _
                        CType(Me.UcStudent.ModelObject, Student), _
                        periodClass)

                db.save(periodClass)

            Next

        End Sub

#End Region



    End Class


End Namespace

